package com.jiangcheng.demo.controller;


import com.jiangcheng.demo.entity.TreeHole;
import com.jiangcheng.demo.service.TreeHoleService;
import com.jiangcheng.demo.utils.NewResult;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.websocket.server.PathParam;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-08-09
 */
@Api("树洞相关API")
@RestController
@RequestMapping("/treeHole")
public class TreeHoleController {
    @Autowired
    TreeHoleService treeHoleService;

    /**
     * 写入树洞
     * @Param String title （标题）
     * @Param String content （内容）
     * @Param Integer U_id （用户ID）
     * return NewResult
     * 参数校验 barnet-valid
     */
    @PostMapping("/write")
    public NewResult write(TreeHole treeHole){
        System.out.println(treeHole);
        return treeHoleService.insert(treeHole);
    }

    /**
     * 查询树洞数据
     * @param Integer page
     * @param Integer pageSize
     * @param Integer uId （过滤的用户）
     */
    @PostMapping("/findTreeHole")
    public NewResult findTreeHole(@Param("page") Integer page,@Param("pageSize") Integer pageSize,@Param("uId") Integer uId){
        return treeHoleService.findTreeHoleByPage(page,pageSize,uId);
    }

    /**
     *  根据用户ID查询树洞的数量
     * @param Integer uId
     */
    @GetMapping("/findTreeHoleCount/{uId}")
    public NewResult findTreeHoleCount(@PathVariable("uId") Integer uId){
        System.out.println(uId);
        return treeHoleService.countByUid(uId);
    }
    @GetMapping("/findTreeHoleByUid/{uId}")
    public NewResult findTreeHoleByUid(@PathVariable("uId") Integer uId){
        System.out.println(uId);
        return treeHoleService.findTreeHoleByUid(uId);
    }
    /**
     * 根据树洞ID查询评论
     * @param Integer tId
     * return NewResult newResult
     */
    @GetMapping("/findCommentByTId/{tId}")
    public NewResult findCommentByTId(@PathVariable("tId") Integer tId){
        return treeHoleService.findCommentByTId(tId);
    }

    /**
     * 根据树洞评论的ID 查询所有回复
     * @param Integer c_id
     */
    @GetMapping("/findReplyByCommentId/{c_id}/{u_id}")
    public NewResult findReplyByCommentId(@PathVariable("c_id") Integer cId,@PathVariable("u_id") Integer uId){
        return treeHoleService.findReplyByCommentId(cId,uId);
    }
}

